package com.company.huisuo.biz.activity

import android.app.Activity
import android.content.Intent
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.company.huisuo.R
import com.company.huisuo.base.BaseActivity
import com.company.huisuo.biz.adapter.FeedBackViewPagerAdapter
import com.company.huisuo.databinding.ActivityFeedBackBinding


class FeedBackActivity : BaseActivity<ActivityFeedBackBinding>() {

    companion object {
        fun start(activity: Activity) {
            activity.startActivity(Intent(activity, FeedBackActivity::class.java))
        }
    }

    override fun initView() {
        mBinding.viewpager.adapter = FeedBackViewPagerAdapter(this)
        mBinding.viewpager.isUserInputEnabled = false
        mBinding.viewpager.registerOnPageChangeCallback(object : OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                mBinding.tvSwitchArtist.isSelected = position == 0
                mBinding.tvSwitchDance.isSelected = position == 1

                val param = mBinding.viewSwitchPoint.layoutParams as ConstraintLayout.LayoutParams
                when (position) {
                    0 -> {
                        param.startToStart = R.id.iv_switch_bg
                        param.endToEnd = ConstraintLayout.LayoutParams.UNSET
                    }
                    1 -> {
                        param.startToStart = ConstraintLayout.LayoutParams.UNSET
                        param.endToEnd = R.id.iv_switch_bg
                    }
                }
                mBinding.viewSwitchPoint.layoutParams = param
            }
        })
        mBinding.tvSwitchArtist.isSelected = true
        mBinding.tvSwitchArtist.setOnClickListener {
            mBinding.viewpager.currentItem = 0
        }
        mBinding.tvSwitchDance.setOnClickListener {
            mBinding.viewpager.currentItem = 1
        }
        mBinding.ivBack.setOnClickListener {
            finish()
        }
    }

    override fun initData() {

    }
}